def qwq():
    n=int(input())
    for i in range(20):
        b=0
        while True:
           a=n%10
           b=b+a*a
           if n//10==0:
               break
           n=n//10
        if b==1:
            return print("True")
        n=b
    return print("False")
qwq()